home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 051-075 / disk_051 / bison / state.h < prev    next >
C/C++ Source or Header  |  1992-05-06  |  5KB  |  129 lines

  1. /* Type definitions for nondeterministic finite state machine for bison,
  2.    copyright (C) 1984 Bob Corbett and Richard Stallman
  3.  
  4.    Permission is granted to anyone to make or distribute verbatim copies of this program
  5.    provided that the copyright notice and this permission notice are preserved;
  6.    and provided that the recipient is not asked to waive or limit his right to
  7.    redistribute copies as permitted by this permission notice;
  8.    and provided that anyone possessing an executable copy
  9.    is granted access to copy the source code, in machine-readable form,
  10.    in some reasonable manner.
  11.  
  12.    Permission is granted to distribute derived works or enhanced versions of
  13.    this program under the above conditions with the additional condition
  14.    that the entire derivative or enhanced work
  15.    must be covered by a permission notice identical to this one.
  16.  
  17.    Anything distributed as part of a package containing portions derived
  18.    from this program, which cannot in current practice perform its function usefully
  19.    in the absense of what was derived directly from this program,
  20.    is to be considered as forming, together with the latter,
  21.    a single work derived from this program,
  22.    which must be entirely covered by a permission notice identical to this one
  23.    in order for distribution of the package to be permitted.
  24.  
  25.  In other words, you are welcome to use, share and improve this program.
  26.  You are forbidden to forbid anyone else to use, share and improve
  27.  what you give them.   Help stamp out software-hoarding!  */
  28.  
  29. /* These type definitions are used to represent a nondeterministic
  30.    finite state machine that parses the specified grammar.
  31.    This information is generated by the function generate_states
  32.    in the file LR0.
  33.  
  34. Each state of the machine is described by a set of items --
  35. particular positions in particular rules -- that are the possible
  36. places where parsing could continue when the machine is in this state.
  37. These symbols at these items are the allowable inputs that can follow now.
  38.  
  39. A core represents one state.  States are numbered in the number field.
  40. When generate_states is finished, the starting state is state 0
  41. and nstates is the number of states.  (A transition to a state
  42. whose state number is nstates indicates termination.)  All the cores
  43. are chained together and first_state points to the first one (state 0).
  44.  
  45. For each state there is a particular symbol which must have been the
  46. last thing accepted to reach that state.  It is the accessing_symbol
  47. of the core.
  48.  
  49. Each core contains a vector of nitems items which are the indices
  50. in the ritems vector of the items that are selected in this state.
  51.  
  52. The link field is used for chaining buckets that hash states by
  53. their itemsets.  This is for recognizing equivalent states and
  54. combining them when the states are generated.
  55.  
  56. The two types of transitions are shifts (push the lookahead token
  57. and read another) and reductions (combine the last n things on the
  58. stack via a rule, replace them with the symbol that the rule derives,
  59. and leave the lookahead token alone).  When the states are generated,
  60. these transitions are represented in two other lists.
  61.  
  62. Each shifts structure describes the possible shift transitions out
  63. of one state, the state whose number is in the number field.
  64. The shifts structures are linked through next and first_shift points to them.
  65. Each contains a vector of numbers of the states that shift transitions
  66. can go to.  The accessing_symbol fields of those states' cores say what kind
  67. of input leads to them.
  68.  
  69. A shift to state zero should be ignored.  Conflict resolution
  70. deletes shifts by changing them to zero.
  71.  
  72. Each reductions structure describes the possible reductions at the state
  73. whose number is in the number field.  The data is a list of nreds rules,
  74. represented by their rule numbers.   first_reduction points to the list
  75. of these structures.
  76.  
  77. There is at least one shift transition present in state zero.
  78. It leads to a next-to-final state whose accessing_symbol is
  79. the grammar's start symbol.  The next-to-final state has one shift
  80. to the final state, whose accessing_symbol is zero (end of input).
  81. The final state has one shift, which goes to the termination state
  82. (whose number is nstates, and for which there is no core structure).
  83. The reason for the extra state at the end is to placate the parser's
  84. strategy of making all decisions one token ahead of its actions.  */
  85.  
  86.  
  87. typedef
  88.   struct core
  89.     {
  90.       struct core *next;
  91.       struct core *link;
  92.       short number;
  93.       short accessing_symbol;
  94.       short nitems;
  95.       short items[1];
  96.     }
  97.   core;
  98.  
  99.  
  100.  
  101. typedef
  102.   struct shifts
  103.     {
  104.       struct shifts *next;
  105.       short number;
  106.       short nshifts;
  107.       short shifts[1];
  108.     }
  109.   shifts;
  110.  
  111.  
  112.  
  113. typedef
  114.   struct reductions
  115.     {
  116.       struct reductions *next;
  117.       short number;
  118.       short nreds;
  119.       short rules[1];
  120.     }
  121.   reductions;
  122.  
  123.  
  124.  
  125. extern int nstates;
  126. extern core *first_state;
  127. extern shifts *first_shift;
  128. extern reductions *first_reduction;
  129.